package org.lanqiao.api.collect;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.service.CartServiceImpl;
import org.lanqiao.service.CollectServieImpI;

@WebServlet("/api/collect/select")
public class SelectCollectServlet  extends HttpServlet {
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		JsonResult result=null;
				
		CollectServieImpI selectCollectServie = new CollectServieImpI();
		//查询传入用户ID
		String userId = request.getParameter("UserId");
		
		List list = selectCollectServie.select(userId);		
		try {	
			if(list.size()>0){	
				result = new JsonResult("查询收藏列表成功",Constants.STATUS_SUCCESS,list);
			}else if(list.size()==0) {
				result = new JsonResult("还没有收藏商品，去发现点商品吧",Constants.STATUS_UNLOGIN);				
			}
			else {				
				result = new JsonResult( "查询失败",Constants.STATUS_UNFOUND);
			}}catch (Exception e) {			
			result = new JsonResult("查询异常",Constants.STATUS_FAILURE,  e.getMessage());
		}

		JsonResultWriter.writer(response, result);


	}

}
